package com.zhoutao123.hephaestus.controller;

import com.zhoutao123.hephaestus.object.bussiness.VBlogComment;
import com.zhoutao123.hephaestus.object.transport.BlogCommentTO;
import com.zhoutao123.hephaestus.service.BlogCommentService;
import eu.bitwalker.useragentutils.UserAgent;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping(value = "/blog-comment")
@Api(tags = "文章评论相关接口")
public class BlogCommentController {

    @Autowired
    BlogCommentService blogCommentService;

    @Autowired
    HttpServletRequest request;

    @PostMapping
    @ApiOperation(value = "增加指定文章的评论")
    public VBlogComment add(@RequestBody BlogCommentTO blogCommentTO) {

        // 获取浏览器信息
        UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent"));

        return blogCommentService.add(blogCommentTO, userAgent);
    }

    @GetMapping()
    @ApiOperation("获取最新的文章评论")
    public List<VBlogComment> getLatestBlogComment(@RequestParam Integer number) {
        return blogCommentService.getLatestComment(number);
    }
}
